<template>
    <view class="content">
        <view class="top">
            <view class="u-flex padding-lr-sm u-rela">
                <view class="u-flex-1">
					<u-search placeholder="搜索内容" v-model="keyword" :show-action="false" height="70" @search="doSearch"></u-search>
				</view>
                <image src="../../static/icon/scan.png" class="scan-icon" @click="scanCode"></image>
            </view>
			
            <timeSearch @doSearch="doSearch" />
            
            <view class="nav">
                <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">待复核</view>
                <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">已复核</view>
            </view>
        </view>
        
        <view class="box text-df" v-for="(item, index) in list" :key="index" 
            @click="$gTo(`/pages/out-check/out-check-details?id=${item.id}&type=${type}`)">
            <view class="item">
                <view class="item-l">订单号</view>
                <view class="item-r">{{item.belong}}</view>
            </view>
            <view class="item">
                <view class="item-l">下单时间</view>
                <view class="item-r">{{item.belong_time}}</view>
            </view>
            <view class="item">
                <view class="item-l">{{ item.type == 1 ? '购货企业' : '供货单位' }}</view>
                <view class="item-r">{{item.shop}}</view>
            </view>
            <view class="item" v-if="item.put_address">
                <view class="item-l">收货地址</view>
                <view class="item-r">{{item.put_address}}</view>
            </view>
            <view class="item" v-if="item.receiver">
                <view class="item-l">收货人员</view>
                <view class="item-r">{{item.receiver}}</view>
            </view>
            <view class="sale-info" v-if="type == 1">
                <view class="item">
                    <view class="item-l">出库人</view>
                    <view class="item-r">{{item.member}}</view>
                </view>
                <view class="item">
                    <view class="item-l">出库时间</view>
                    <view class="item-r">{{item.create_time}}</view>
                </view>
            </view>
            <view class="sale-info" v-if="type == 2">
                <view class="item">
                    <view class="item-l">复核人</view>
                    <view class="item-r">{{item.member}}</view>
                </view>
                <view class="item">
                    <view class="item-l">复核时间</view>
                    <view class="item-r">{{item.create_time}}</view>
                </view>
            </view>
            <view class="btn-square blue" v-if="type == 1">复核</view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
                type: 1,
                keyword: '',
                startTime: '',
                endTime: '',
				
            };
        },
        onShow() {
			if (!this.$getSync('SCANCODE')) {
				this.list = []
				this.page = 1
				this.status = 'loadmore'
				this.getList()
			}
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
			scanCode() {
				this.$setSync('SCANCODE',1)
				this.$scanCode((res) => {
				    console.log('000',res, res.result)
					this.keyword = res.result
					this.page = 1;
					this.list = [];
					this.status = 'loadmore';
				    this.getList()
				})
			},
			
            doSearch(data) {
                if (data) {
                    this.startTime = data.startTime
                    this.endTime = data.endTime
                }
                this.page = 1;
                this.list = [];
                this.status = 'loadmore';
                this.getList()
            },
            
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
                let url = ''
                if (this.type == 1) {
                    // 已出库 待复核
                    url = 'inventory_out/reply_list'
                } else {
                    // 已复核 待运输
                    url = 'inventory_out/double_check_list'
                }
                
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax(url, {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    keywords: this.keyword,
                    start_time: this.startTime,
                    end_time: this.endTime,
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
						this.$removeSync('SCANCODE')
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f5f5f5 !important;
    }
    .top{
        background-color: #fff;
    }
    .scan-icon{
        width: 40rpx;
        height: 40rpx;
		margin-left: 30rpx;
        // position: absolute;
        // right: 65rpx;
        // top: 50%;
        // transform: translateY(-50%);
    }
    
    .nav{
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav-i{
        width: calc(100vw / 2);
        font-size: 30rpx;
        font-weight: bold;
        text-align: center;
        padding-bottom: 30rpx;
    }
    .active{
        color: #ff4800;
        position: relative;
    }
    .active::after{
        display: block;
        content: '';
        width: 32rpx;
        height: 8rpx;
        background-color: #ff4800;
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
    }
    
    
    .box{
        background-color: #fff;
        border-radius: 15rpx;
        padding: 30rpx 15rpx;
        margin: 25rpx 25rpx 0;
    }
    .sale-info{
        padding: 20rpx 0;
        background-color: #f5f6f8;
        border-radius: 10rpx;
        margin-top: 15rpx;
    }
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0 20rpx 15rpx;
    }
    .item:last-child{
        padding-bottom: 0;
    }
    .item-l{
        width: 150rpx;
        color: #868686;
    }
    .item-r{
        flex: 1;
        word-break: break-all;
        white-space: pre-line;
    }
    .blue{
        background-color: #0780f6;
        margin-top: 20rpx;
        padding: 20rpx;
    }

</style>
